﻿using UnityEngine;
using System.Collections;

public class ThreatMapScript : MonoBehaviour {

    public int size;

    private bool Started = false;
    private ThreatEngine mThreatEngine;

	// Use this for initialization
	void Start () 
    {
        mThreatEngine = new ThreatEngine(size, size);
        Started = true;
        mThreatEngine.SetCellDampening(25, 10, 1);
        mThreatEngine.SetCellDampening(25, 11, 1);
        mThreatEngine.SetCellDampening(25, 12, 1);
        mThreatEngine.SetCellDampening(25, 13, 1);
        mThreatEngine.SetCellDampening(25, 14, 1);

        mThreatEngine.SetCellDampening(15, 30, 1);
        mThreatEngine.SetCellDampening(16, 29, 1);
        mThreatEngine.SetCellDampening(17, 28, 1);
        mThreatEngine.SetCellDampening(18, 27, 1);
        mThreatEngine.SetCellThreat(10, 10, .5f);
        mThreatEngine.SetCellThreat(10, 12, .5f);
        mThreatEngine.SetCellThreat(13, 20, .5f);
	}
	
	// Update is called once per frame
	void Update ()
    {
        mThreatEngine.Update();
	}

    public void SetCellDampening(int x, int y, float dampening)
    {
        mThreatEngine.SetCellDampening(x, y, dampening);
    }

    void OnDrawGizmos()
    {
        if (Started)
        {
            Gizmos.color = Color.red;
            for (int x = 0; x < size; x++)
            {
                for (int y = 0; y < size; y++)
                {
                    Vector3 position = new Vector3(x, 0, y);
                    for (DirectionEnum direction = DirectionEnum.First; direction < DirectionEnum.Count; direction++)
                    {
                        Vector3 outVect = mThreatEngine.GetCellDirection(x, y, direction);
                        
                        if (outVect.sqrMagnitude > .05f)
                        {
                            Gizmos.DrawRay(position, outVect);
                        }
                    }
                    //Gizmos.DrawCube(position, new Vector3(.1f, .1f, .1f));
                }
            }
            Gizmos.color = Color.green;
            Gizmos.DrawSphere(new Vector3(13f, 0, 20f), .3f);
            Gizmos.DrawSphere(new Vector3(10f, 0, 12f), .3f);
            Gizmos.DrawSphere(new Vector3(10f, 0, 10f), .3f);
            Gizmos.color = Color.blue;
            Gizmos.DrawCube(new Vector3(25f, 0, 10f), Vector3.one);
            Gizmos.DrawCube(new Vector3(25f, 0, 11f), Vector3.one);
            Gizmos.DrawCube(new Vector3(25f, 0, 12f), Vector3.one);
            Gizmos.DrawCube(new Vector3(25f, 0, 13f), Vector3.one);
            Gizmos.DrawCube(new Vector3(25f, 0, 14f), Vector3.one);

            Gizmos.DrawCube(new Vector3(15f, 0, 30f), Vector3.one);
            Gizmos.DrawCube(new Vector3(16f, 0, 29f), Vector3.one);
            Gizmos.DrawCube(new Vector3(17f, 0, 28f), Vector3.one);
            Gizmos.DrawCube(new Vector3(18f, 0, 27f), Vector3.one);
        }
    }
}
